package cn.edu.suse.epilepsy.controller;

import cn.edu.suse.epilepsy.common.BizException;
import cn.edu.suse.epilepsy.common.R;
import cn.edu.suse.epilepsy.entity.dto.PageDto;
import cn.edu.suse.epilepsy.entity.pojo.PatientEduActivity;
import cn.edu.suse.epilepsy.service.PatientEduActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/activity")
public class PatientEduActivityController {
    @Autowired
    private PatientEduActivityService patientEduActivityService;

    /**
     * 分页查询患教活动
     * @param pageDto
     * @return
     */
    @GetMapping("/query")
    public R query(PageDto pageDto){
        log.info("patient分页查询，参数： {}", pageDto);
        return patientEduActivityService.getAll(pageDto);
    }

    /**
     * 删除患教活动
     * @param id
     * @return
     */
    @PostMapping("/deleteActivity/{id}")
    public R deleteActivity(@PathVariable("id") Integer id){

        boolean b = patientEduActivityService.removeById(id);
        if(b){
            return R.success();
        }
        return R.failed();
    }

    /**
     * 新增患教活动
     */
    @PostMapping("/add")
    public R addActivity(@RequestBody PatientEduActivity patientEduActivity){

        return patientEduActivityService.addPatient(patientEduActivity);
    }

    /**
     * 编辑环礁活动
     * @param patientEduActivity
     * @return
     */
    @PostMapping("/update")
    public R updateActivity(@RequestBody PatientEduActivity patientEduActivity){

        int update = patientEduActivityService.getBaseMapper().updateById(patientEduActivity);
        if(update>0){
            return R.success();
        }
        return R.failed();
    }

    @GetMapping("/get/{id}")
    public R getById(@PathVariable("id") Integer id){
        PatientEduActivity patientEduActivity = patientEduActivityService.getById(id);
        return R.success(patientEduActivity);
    }

}
